<?php

include_once 'Expression.php';
include_once 'UnaryOperator.php';

/**
 * Represents an unary operator expression
 * 
 * @package UC_PHPCodeModel
 * @author Uros Calakovic
 * @example ../Examples/UnaryOperatorExpressionExample.php 
 */

class UnaryOperatorExpression extends Expression
{
    /**
     * UnaryOperatorExpression constructor
     * 
     * @param UnaryOperator $operator One of the UnaryOperator constants
     * @param Expression $expression The expression on the left of the operator
     */
    
    public function __construct($operator, Expression $expression = null)
    {
        parent::__construct();
        
        $expression == null ? 
            $this->Expression = new Expression() : 
            $this->set_Expression($expression);
        
        $this->set_Operator($operator);
    }
    
    /**
     * Used for making private / protected variables 
     * accessible from outside the class.
     * 
     * @param string $name Name of the field to be accessed
     * @param mixed $value The value the field should be set to, usually a collection.
     * @see CodeObject::__set()
     */
    
    public function __set($name, $value)
    {
        parent::__set($name, $value);
        
        if($name == 'Expression')
        {
            $this->set_Expression($value);
        }
        
        if($name == 'Operator')
        {
            $this->set_Operator($value);
        }
    }

    /**
     * Used for making private / protected variables 
     * accessible from outside the class.
     * 
     * @param string $name Name of the field to be accessed
     * @return mixed The field that $name specified, usually a collection
     * @see CodeObject::__get()
     */
    
    public function __get($name)
    {
        $ret = parent::__get($name);
        
        if($ret != null)
        {
            return $ret;
        }
        
        if($name == 'Expression')
        {
            return $this->get_Expression();
        }
        
        if($name == 'Operator')
        {
            return $this->get_Operator();
        }
    }
    
    /**
     * The $Expression getter method
     * @return Expression 
     */
    
    public function get_Expression()
    {
        return $this->Expression;
    }

    /**
     * The $Expression setter method
     * @param Expression $Expression 
     * 
     * @assert (123) throws PHPUnit_Framework_Error
     * @assert ('name') throws PHPUnit_Framework_Error
     */
    
    public function set_Expression(Expression $Expression)
    {
        $this->Expression = $Expression;
    }

    /**
     * The $Operator getter method
     * @return UnaryOperator 
     */
    
    public function get_Operator()
    {
        return $this->Operator;
    }

    /**
     * The $Operator setter method
     * @param type $Operator
     * @throws InvalidArgumentException If $Operator is not one of the UnaryOperator constants
     * 
     * @assert (123) throws InvalidArgumentException
     * @assert ('name') throws InvalidArgumentException
     */
    
    public function set_Operator($Operator)
    {
        if(is_string($Operator))
        {
            if(UnaryOperator::Defines($Operator))
            {
                $this->Operator = $Operator;
            }
            else
            {
                throw new InvalidArgumentException(
                    'The parameter must be a ' . 
                    'UnaryOperator class constant.');
            }
        }
        else
        {
            throw new InvalidArgumentException(
                'The parameter must be a ' . 
                'UnaryOperator class constant.');
        }
    }

    /**
     * The unary operator expression
     * @var Expression 
     */
    
    private $Expression;
    
    /**
     * One of the UnaryOperator constants
     * @var UnaryOperator
     * @see UnaryOperator 
     */
    
    private $Operator;
}

?>
